package cn.kgc.javaweb.service.impl;

import cn.kgc.javaweb.dao.StudentDao;
import cn.kgc.javaweb.dao.StudentDaoImpl;
import cn.kgc.javaweb.dao.UserDao;
import cn.kgc.javaweb.entity.Student;
import cn.kgc.javaweb.service.StudentService;
import cn.kgc.javaweb.util.Result;

import java.util.List;

/**
 * @author: mosin
 * @version: v1.0  2022/3/25
 */
public class StudentServiceImpl implements StudentService {
    private StudentDao studentDao = new StudentDaoImpl();

    @Override
    public Result<List<Student> > selectByPage(int page, int limit) {

         List<Student> students = studentDao.findByPage(page,limit);
         long count = studentDao.selectTotal();

        Result<List<Student>> result = new Result<>();
        result.setCount(count);
        result.setCode(0);
        result.setMsg("查成功");
        result.setData(students);

        return result;
    }

    @Override
    public boolean addStudent(Student student) {

        int line = studentDao.insertStudent(student);
        return line>0;
    }

    @Override
    public boolean updateStudent(Student student) {
       int line =  studentDao.update(student);
       return line>0;
    }

    @Override
    public boolean delStudent(int id) {

       int line = studentDao.del(id);
        return line>0;
    }
}
